package com.sky.controller.user;

import com.sky.entity.AddressBook;
import com.sky.result.Result;
import com.sky.service.AddressBookService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("user/addressBook")
@Slf4j
public class AddressBookController {
    @Autowired
    private AddressBookService addressBookService;

    @GetMapping("list")
    public Result<List<AddressBook>> list(){
        List<AddressBook> list=addressBookService.list();
        return Result.success(list);
    }

    @PostMapping("")
    public Result<Object> add(@RequestBody AddressBook addressBook){
        log.info("{}",addressBook);
        addressBookService.add(addressBook);
        return Result.success();
    }

    @GetMapping("default")
    public Result<AddressBook> getDefault(){
       AddressBook addressBook= addressBookService.getDefault();
       return Result.success(addressBook);
    }

    @PutMapping("default")
    public Result<Object> setDefault(@RequestBody AddressBook addressBook){
        log.info("{}",addressBook);
        addressBookService.setDefault(addressBook);
        return Result.success();
    }
}
